package org.lmind.example.util.text;

import static org.junit.Assert.*;

import org.junit.Test;
import org.lmind.example.util.text.PlaceholderResolver.Resolver;

public class PlaceholderResolverTestCase {
	
	@Test
	public void test1() {
		PlaceholderResolver pr = new PlaceholderResolver("${", "}");
		Resolver r = pr.resolver("The ${user.name} send a mail ${user.mail} !");
		while (r.next()) {
			if (r.getKey().equals("user.name")) {
				r.replace("mian.liu");
			} else if (r.getKey().equals("user.mail")) {
				r.replace("mian.liu@yeepay.com");
			}
		}
		
		r.next();
		String ret = r.build();
		assertEquals(ret, "The mian.liu send a mail mian.liu@yeepay.com !");
	}

	@Test
	public void test2() {
		PlaceholderResolver pr = new PlaceholderResolver("${", "}");
		Resolver r = pr.resolver("The ${user.name} send a mail ${user.mail} !");
		while (r.next()) {
			if (r.getKey().equals("user.name")) {
				r.replace("mian.liu");
			} else if (r.getKey().equals("user.mail")) {
				r.replace("mian.liu@yeepay.com");
			}
			break;
		}
		String ret = r.build();
		assertEquals(ret, "The mian.liu send a mail ${user.mail} !");
	}
}
